package com.lkqandzzy.controller;

import com.lkqandzzy.entity.User;
import com.lkqandzzy.mapper.RankMapper;
import com.lkqandzzy.util.HostHolder;
import com.lkqandzzy.util.JedisAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Set;

/**
 * @author 邹靓仔
 * @date 2020/5/28 -21:43 -blog
 **/
@Controller
public class RankController {
    @Autowired
    private HostHolder hostHolder;

    @Autowired
    private RankMapper rankMapper;

    @Autowired
    private JedisAdapter jedisAdapter;

    private String rankKey="forumRankKey";

    @RequestMapping(path="/rank",method= RequestMethod.GET)
    public String rankPoint(Model model) {
     /*   User user=hostHolder.getUser();*/

        User user=new User();
        user.setId(8L);
        user.setUsername("凌康乾");
        Long points = rankMapper.getPoints(user.getId());
        jedisAdapter.zadd(rankKey, points, user.getUsername());
        Set<String> pointSet=jedisAdapter.zrevrange(rankKey, 0, 9);
        model.addAttribute("user", user);
        /*model.addAttribute("newMessage", messageDao.countMessageByToId(user.getId()));*/
        model.addAttribute("pointSet", pointSet);
        model.addAttribute("rankMapper", rankMapper);
        return "rank";
    }
}
